package com.huc.rabbit.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 发布订阅
 */
@Configuration
public class RabbitPublishSubscribeConfig {

    public static final String QUEUE_NAME_A = "push.sub.a";
    public static final String QUEUE_NAME_B = "push.sub.b";

    public static final String EXCHANGE_NAME = "push.sub.exchange";

    @Bean
    public Queue queuePushA(){
        return new Queue(QUEUE_NAME_A,true);
    }

    @Bean
    public Queue queuePushB(){
        return new Queue(QUEUE_NAME_B,true);
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange(EXCHANGE_NAME);
    }

    @Bean
    public Binding bindingQueueA2FanoutExchange(Queue queuePushA,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queuePushA).to(fanoutExchange);
    }

    @Bean
    public Binding bindingQueueB2FanoutExchange(Queue queuePushB,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queuePushB).to(fanoutExchange);
    }



}
